package com.disapand.strongarmy.model

import org.ktorm.database.*
import org.ktorm.entity.*
import org.ktorm.schema.*
import java.time.*

/**
 *
 * @auth disapand
 * @date 2021/10/26 - 16:37 - 星期二
 *
 */
interface Permission: Entity<Permission> {
    companion object: Entity.Factory<Permission>()

    val id: Int
    var group: String
    var groupLabel: String
    var label: String
    var method: String
    var permission: String
    var createdAt: LocalDateTime
    var updatedAt: LocalDateTime
}

object Permissions: Table<Permission>("sa_permission") {
    val id = int("id").primaryKey().bindTo { it.id }
    val group = varchar("group").bindTo { it.group }
    val groupLabel = varchar("group_label").bindTo { it.groupLabel }
    val label = varchar("label").bindTo { it.label }
    val method = varchar("method").bindTo { it.method }
    val permission = varchar("permission").bindTo { it.permission }
    val createdAt = datetime("created_at").bindTo { it.createdAt }
    val updatedAt = datetime("updated_at").bindTo { it.updatedAt }
}

val Database.permissions get() = this.sequenceOf(Permissions)